﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevComponents.DotNetBar;

namespace GiangDay
{
    public partial class FrKhoa : DevComponents.DotNetBar.Office2007Form
    {
        FunctionLinh fun = new FunctionLinh();
        DB db = new DB();
        public FrKhoa()
        {
            InitializeComponent();
        }

        private void FrKhoa_Load(object sender, EventArgs e)
        {
            dgKhoa.DataSource = fun.loadkhoa();
        }     
       
        private void btThem_Click(object sender, EventArgs e)
        {
            FrKhoaYearAdd fr = new FrKhoaYearAdd();
            fr.khoa = this;
            fr.ShowDialog();
        }       
        private void txtnamhoc_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (!char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar))
            { e.Handled = true; }
            if (e.KeyChar == 13) //gởi phím tab khi nhấn enter
                SendKeys.Send("{tab}");
         
        }
        public void loadGrid()
        {
            dgKhoa.DataSource = fun.loadkhoa();
        }
        private void bt_suakhoa_Click(object sender, EventArgs e)
        {
            //if (txtmakhoa.Text == "")
            //{
            //    MessageBox.Show("Chưa chọn Khoa cần sữa", "Thông báo", MessageBoxButtons.OK, MessageBoxIcon.Information);
            //    return;
            //}

            //if (fun.suaKHOA(txtmakhoa.Text,txttenkhoa.Text,int.Parse(txtnamhoc.Text)))
            //{
            //    dgkhoa.Rows[dgkhoa.CurrentRow.Index].Cells["TEN_KHOA"].Value = txttenkhoa.Text;
            //    dgkhoa.Rows[dgkhoa.CurrentRow.Index].Cells["NAM_HOC"].Value = int.Parse(txtnamhoc.Text);
            //    txtmakhoa.Clear();
            //    txttenkhoa.Clear();
            //    txtnamhoc.Clear();
            //}
        }

        private void bt_xoakhoa_Click(object sender, EventArgs e)
        {           
            //fun.xoaKHOA(txtmakhoa.Text);
            //dgkhoa.DataSource = fun.loadkhoa();

        }

        private void dgKhoa_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            if (dgKhoa.SelectedRows.Count == 0 || dgKhoa.Rows[dgKhoa.CurrentRow.Index].Cells["MA_KHOA"].Value.ToString()=="")
            {               
                btXoa.Enabled = false;
                return;
            }           
            btXoa.Enabled = true;
            //txtmakhoa.Text = dgkhoa.Rows[dgkhoa.CurrentRow.Index].Cells["MA_KHOA"].Value.ToString();
            //txttenkhoa.Text = dgkhoa.Rows[dgkhoa.CurrentRow.Index].Cells["TEN_KHOA"].Value.ToString();
            //txtnamhoc.Text = dgkhoa.Rows[dgkhoa.CurrentRow.Index].Cells["NAM_HOC"].Value.ToString();
        }

        private void btXoa_Click(object sender, EventArgs e)
        {
            if (dgKhoa.RowCount==1)       return;          
            fun.delKhoa(dgKhoa.Rows[dgKhoa.CurrentRow.Index].Cells["MA_KHOA"].Value.ToString());
            dgKhoa.Rows.RemoveAt(dgKhoa.CurrentRow.Index);
        }

        private void btSua_Click(object sender, EventArgs e)
        {
           // dgKhoa.Rows.AddCopies(2, 1);
        }
       
    }
}